﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using agent02.com.somee.g02airplane;
using agent02.Model;

namespace agent02.Controllers
{
    public class AirplaneController : Controller
    {
        AgentDBEntities db = new AgentDBEntities();

        //
        // GET: /Airplane/
        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /Airplane/Search
        public ActionResult Search()
        {
            AirplaneSearchModel a = new AirplaneSearchModel();
            return View(a);
        }

        [HttpPost]
        public ActionResult Search(AirplaneSearchModel a)
        {
            return RedirectToAction("SearchResult", new { sanbaydi = a.sanBayDi, sanbayden = a.sanBayDen });
        }

        //
        // GET: /Airplane/SearchResult
        public ActionResult SearchResult(string sanbaydi, string sanbayden)
        {
            WebService_AirPlane ws = new WebService_AirPlane();
            DataSet ds = ws.TimChuyenBay_SanBay_Di_Den(sanbaydi, sanbayden);
            AirplaneSearchResultModel a = new AirplaneSearchResultModel();
            
            return View(a.ConvertToFLIGHT(ds.Tables[0]));
        }
    }
}
